package com.final_adm.utils;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Una clase para manejar la creación de la base de datos.
 * Aquí guardaremos los datos que no se puedan subir al servidor
 * En principio solo los tracks y eventos 
 */
public class MySqlHelper extends SQLiteOpenHelper {
    // All Static variables 
    // Database Name
    private static final String DATABASE_NAME = "database.db";
 
    // Nombre de las tablas
    private static final String TABLA_TRACK = "track";
    private static final String TABLA_EVENTO = "evento";
    
    // Columnas Tabla TRACK
    private static final String TRACK_ID = "id_track"; //ESTE SE NO VA A CORRESPONDER CON EL DEL SERVIDOR
    private static final String TRACK_DEPORTE = "deporte";
    private static final String TRACK_FINI = "fecha_inicio";
    private static final String TRACK_FFIN = "fecha_fin";
    private static final String TRACK_DURACION = "duracion"; //DURACION EN SEGUNDOS
    private static final String TRACK_PUNTOS = "puntos";
    private static final String TRACK_CALORIAS = "calorias";
    private static final String TRACK_PULSACIONES = "pulsaciones";
    private static final String TRACK_DISTANCIA = "distancia";
    
    
	public MySqlHelper(Context context) {
		super(context, DATABASE_NAME, null, 1);
	}
	
	@Override
	public void onCreate(SQLiteDatabase arg0) {
		// Create here the DB by code
        String CREAR_TABLA_TRACK = "CREATE TABLE " + TABLA_TRACK + "("
                + TRACK_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + TRACK_DEPORTE + " INTEGER NOT NULL,"
                + TRACK_FINI + " TEXT," + TRACK_FFIN + " TEXT," 
                + TRACK_DURACION + " INTEGER NOT NULL," + TRACK_PUNTOS + " TEXT,"
                + TRACK_CALORIAS + " INTEGER," + TRACK_PULSACIONES + " REAL,"
                + TRACK_DURACION + " REAL"
                + ")";
		arg0.execSQL(CREAR_TABLA_TRACK);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Autogenerated method stub
	}
	
	
    // Adding new score
	/*public void addScore(HighScore score) {
		SQLiteDatabase db = this.getWritableDatabase();
	
		ContentValues values = new ContentValues();
		values.put(KEY_NAME, score.getName()); // Contact Name
		values.put(KEY_SCORE, score.getScoring()); // Contact Phone Number
		
		db.delete(TABLA_PUNTIACIONES,KEY_NAME+" = '"+score.getName()+"' AND "+KEY_SCORE+" = "+score.getScoring() ,null);
		
		// Inserting Row
		db.insert(TABLA_PUNTIACIONES, null, values);
		db.close(); // Closing database connection
	}
	
		// 	borrar puntuaciones
		public void borrarScores() {
			SQLiteDatabase db = this.getWritableDatabase();
		
			db.delete(TABLA_PUNTIACIONES, null, null);
			db.close(); // Closing database connection
		}
	*/
	
	
	// Obtener todas las puntiaciones
	/*public List<HighScore> getAllScores() {
		List<HighScore> scoresList = new ArrayList<HighScore>();
		// Select All Query
		String selectQuery = "SELECT  * FROM " + TABLA_PUNTIACIONES +" ORDER BY "+ KEY_SCORE +" DESC";

		SQLiteDatabase db = this.getReadableDatabase();
		Cursor cursor = db.rawQuery(selectQuery, null);

		// looping through all rows and adding to list
		if (cursor.moveToFirst()) {
			do {
				HighScore score = new HighScore();
				score.setId(Integer.parseInt(cursor.getString(0)));
				score.setName(cursor.getString(1));
				score.setScoring(Integer.parseInt(cursor.getString(2)));
				// Adding contact to list
				scoresList.add(score);
			} while (cursor.moveToNext());
		}
		
		cursor.close();
		db.close();
		// return contact list
		return scoresList;
	}*/
	

}